#include <iostream>
using namespace std;

//error
class LCA {
public:
    static int getLCA(int a, int b) {
        // write code here

        if (a < b) swap(a, b);

        while ((a / b) >= 2)
        {
            a /= 2;
        }

        int par1 = a, par2 = b;
        while (par1 != par2)
        {
            par1 /= 2;
            par2 /= 2;
        }

        return par1;
    }
};

int main()
{

    cout << LCA::getLCA(10, 12);
    
    return 0;
}

#include <cstdlib>
#include <vector>
class LCA {
public:
    int getLCA(int a, int b) {
        // write code here

        vector<int> t_a;
        vector<int> t_b;

        while (a > 0 || b > 0)
        {
            if (a > 0)
            {
                t_a.push_back(a);
                a /= 2;
            }

            if (b > 0)
            {
                t_b.push_back(b);
                b /= 2;
            }
        }

        for (int i = 0; i < t_a.size(); i++)
        {
            for (int j = 0; j < t_b.size(); j++)
            {
                if (t_a[i] == t_b[j]) return t_a[i];
            }
        }
        return 1;
    }
};